package cn.tedu.mall.seckill.config;

import cn.tedu.mall.seckill.timer.InitailBloomJob;
import cn.tedu.mall.seckill.timer.SeckillInitialJob;
import lombok.extern.slf4j.Slf4j;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@Slf4j
public class QuartzConfig {
    //定义JobDetail封装SeckillInitialJob
    @Bean
    public JobDetail initJobDetail(){
        log.info("预热任务开始运行");
        return JobBuilder.newJob(SeckillInitialJob.class)
                .withIdentity("initailJobDetail")
                .storeDurably()
                .build();
    }

    //定义Trigger
    @Bean
    public Trigger initTrigger(){
        log.info("预热触发器开始运行");
        CronScheduleBuilder cron = CronScheduleBuilder.cronSchedule("0 0/1 * * * ?");
        return TriggerBuilder.newTrigger()
                .forJob(initJobDetail())
                .withIdentity("initailTrigger")
                .withSchedule(cron)
                .build();
    }
    //定义JobDetail封装SeckillBloomInitialJob
    @Bean
    public JobDetail initBloomDetail(){
        log.info("布隆过滤器任务开始运行");
        return JobBuilder.newJob(InitailBloomJob.class)
                .withIdentity("initBloomDetail")
                .storeDurably()
                .build();
    }

    //定义Trigger
    @Bean
    public Trigger initBloomTrigger(){
        log.info("预热触发器开始运行");
        CronScheduleBuilder cron = CronScheduleBuilder.cronSchedule("0 0/1 * * * ?");
        return TriggerBuilder.newTrigger()
                .forJob(initBloomDetail())
                .withIdentity("initBloomTrigger")
                .withSchedule(cron)
                .build();
    }
}
